﻿using System.Drawing;
using RaytracerLib.Layers;
using RaytracerLib.MathLib;
using TomanuExtensions;
using YAXLib;
using System.Diagnostics;
using System.Numerics;

namespace RaytracerLib.Postprocessing
{
    public class FFT2Transform : Postprocessor
    {
        [YAXNode]
        public double Scale = 0.01;

        internal override void PostprocessFinalize(ColorArrayFloat a_ar)
        {
            double[,] ar = new double[a_ar.Width, a_ar.Height];

            foreach (var p in a_ar.Pixels())
                ar[p.X, p.Y] = a_ar[p.X, p.Y].Avg;

            Complex[,] car = FFT.fft2(ar);

            car = FFT.fftshift(car);

            foreach (var p in a_ar.Pixels())
            {
                double v = car[p.X, p.Y].Magnitude;
                v *= Scale;
                a_ar[p.X, p.Y] = new ColorFloat(v);
            }
        }
    }
}